<!DOCTYPE html>
<html>
<head>
    <meta charset="utf8">
    <title>在线音乐网</title>
    <link href="{{ url_for('static',filename='css/pt_discover_index.css')}}" type="text/css" rel="stylesheet">
    <link href="{{ url_for('static',filename='css/pt_frame.css')}}" type="text/css" rel="stylesheet">
    <script type="text/javascript" src="{{url_for('static',filename='js/jquery-2.2.0.min.js')}}"></script>
    <script type="text/javascript" src="{{url_for('static',filename='js/layer/layer.js')}}"></script>
</head>
<body style="">
    <div data-module="" data-sub="" id="g_top" class="m-top">
        &nbsp;
    </div>
    <div class="g-bd" style="margin-top:-80px;">
        <div class="g-wrap" id="baseBox">
            <div class="u-title u-title-2 f-cb">
                <h3>
                    <span class="f-ff2">后台管理</span>
                </h3>
            </div>
            <ul class="m-tabs f-cb">
                <li class="fst">
                    <a href="{{url_for('home.manageArtist')}}" ><em>歌手</em> </a>
                </li>
                <li>
                    <a href="{{url_for('home.manageSong')}}" class="z-slt"><em>歌曲</em> </a>
                </li>
                 {% if session['flag']==2 %}
                    <li>
                        <a href="{{url_for('home.manageAdmin')}}"><em>管理员</em></a>
                    </li>
                {% endif %}
                 <li>
                    <a href="{{url_for('home.manageUser')}}"><em>用户</em></a>
                </li>
                <li>
                    <a href="{{url_for('home.taglist')}}" ><em>类别</em> </a>
                </li>
            </ul>
            <div class="g-wrap p-prf" style="height:800px;">
                <div class="n-bind f-cb j-flag">
                    <p class="delete">
                        <a target="contentFrame" href={{url_for('home.manageSongAdd')}} class="btn"><i>新增歌曲</i>
                        </a>
                    </p>
                </div>
                <div class="u-title u-title-1 f-cb m-record-title" id="rHeader" >
                    <h3>
                        <span class="f-ff2 s-fc3">歌曲列表</span>
                    </h3>
                </div>
                <div id="m-record" data-uid="3514008" data-songs="1316" class="m-record">
                    <div id="auto-id-oXK37yPmGlBEcCTf">
                        <div class="j-flag" id="auto-id-42i2wAet2Pki6UW6">
                            <table class="m-table m-table-rank">
                                <thead>
                                    <tr>
                                        <th>
                                            <div class="wp">
                                                歌曲
                                            </div>
                                        </th>
                                        <th class="wp">
                                            <div class="wp">
                                                歌手
                                            </div>
                                        </th>
                                        <th class="w3">
                                            <div class="wp">
                                                类别
                                            </div>
                                        </th>
                                        <th class="w3">
                                            <div class="wp">
                                                操作
                                            </div>
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {% for song in page_data.items %}
                                    <tr>
                                        <td class="rank">
                                            {{song.songName}}
                                        </td>
                                        <td class=" s-fc3">
                                            {{song.singer}}
                                        </td>
                                        <td class=" s-fc3">
                                           {{ song.tag.name }}
                                        </td>
                                        <td class="">
                                            <a href="{{url_for('home.manageSongEdit',id=song.id)}}">修改</a>
                                            <a href="javascript:;" class="del" data-id="{{song.id}}">删除</a>
                                        </td>
                                    </tr>
                                    {% endfor %}
                                </tbody>
                            </table>
                            <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                    <td height="24" align="right">
                                        当前页数：[{{page_data.page}}/{{page_data.pages}}]&nbsp;
                                        <a href="{{ url_for('home.manageSong',page=1) }}">第一页</a>
                                            {% if page_data.has_prev %}
                                              <a href="{{ url_for('home.manageSong',page=page_data.prev_num) }}">上一页</a>
                                            {% endif %}
                                            {% if page_data.has_next %}
                                        　     <a href="{{ url_for('home.manageSong',page=page_data.next_num) }}">下一页</a>
                                            {% endif %}　
                                        <a href="{{ url_for('home.manageSong',page=page_data.pages) }}">最后一页&nbsp;</a>
                                    </td>
                                </tr>
                            </table>
                        </div>
                        <div class="j-flag"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(document).ready(function() {
            $('.del').click(function(){
                var id = $(this).data('id');
                layer.confirm('确认删除', function(){
                    $.ajax({
                        url: "{{ url_for('home.manageSongDel') }}",
                        type: "GET",
                        data: {id: id},
                        dataType: "json",
                        success: function (res) {
                            if (res.status == 1) {
                                layer.msg(res.message, {icon: 1, time: 2000}, function(){
                                    window.location.reload(); // Reload the page after successful deletion
                                });
                            } else {
                                layer.msg(res.message, {icon: 2, time: 2000});
                            }
                        },
                        error: function(xhr, status, error) {
                            console.error(xhr.responseText); // Log the error to the console for debugging
                            layer.msg('An error occurred while deleting the song.', {icon: 2, time: 2000});
                        }
                    });
                });
            });
        });
    </script>
</body>
</html>
